<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        html,body{
            width: 100%;
            height: 100%;
        }
        .btn{
            text-decoration: none;
            font-size: 30px;
        }
        .box{
            display: none;
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0,0,0,.3);
        }
        .mask{
            display: none;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%,-50%);
            width: 300px;
            height: 300px;
            background-color: #fff;
        }
    </style>
</head>
<body>
    <a href="#" class="btn">注册</a>
    <div class="box"></div>
    <div class="mask"></div>
</body>
</html>
<script>
    var btn = document.querySelector('.btn')
    var box = document.querySelector('.box')
    var mask = document.querySelector('.mask')
    btn.onclick = function(event){
        event = event || window.event
        box.style.display = 'block'
        mask.style.display = 'block'
        // 阻止冒泡
        if(event.stopPropagation){
            event.stopPropagation()
        }else{
            event.cancelBubble = true
        }
    }
    document.onclick = function(){
        box.style.display = 'none'
        mask.style.display = 'none'
    }
</script>